package day06;

import java.util.Random;

/*
已经产生了5个不重复的大写字母
请猜这5个字母
    GXYQC
 猜 CQYAC
 */

public class GuessLetterGame extends GuessGame{

    @Override
    public String genRandom() {
        char[] c = new char[5];
        for(int i = 0; i < c.length; i++){
            c[i] = (char)(65 + new Random().nextInt(26));
        }
        return String.valueOf(c);
    }

    @Override
    public void hint() {
        System.out.println("已经产生从A-Z中随机产生的五个字母");
        System.out.println("看你能猜中其中的几个?");
    }

    @Override
    public String compareResult(String c, String r) {
        char[] input = c.toCharArray();
        char[] result = r.toCharArray();
        int countA = 0;
        int countB = 0;
        for(int i = 0; i< input.length; i++){
            for(int j = 0; j < result.length; j++){
                if(input[i] == result[j] && i == j){
                    countA += 1;
                }else if(input[i] == result[j]){
                    countB += 1;
                }
            }
        }
        return countA+"A"+countB+"B";
    }

    @Override
    public boolean guessRight(String result) {
        return "5A0B".equals(result);
    }
}
